package com.fjut.controller;


import com.fjut.model.activity.CouponInfo;
import com.fjut.model.activity.CouponUse;
import com.fjut.result.Result;
import com.fjut.service.CouponInfoService;
import com.fjut.vo.activity.CouponUseQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 优惠券信息 前端控制器
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-09
 */
@Api(tags = "优惠券接口")
@RestController
@RequestMapping("/fjut/activity/couponInfo")
public class CouponInfoController {

    @Autowired
    private CouponInfoService couponInfoService;

    @ApiOperation("获取未使用优惠券信息")
    @GetMapping("getCouponUnusedInfo")
    public Result getCouponUnusedInfo(){
        return Result.success(couponInfoService.getCouponUnusedInfo());
    }

    @ApiOperation("获取优惠券信息")
    @GetMapping("getCouponInfo/{id}")
    public Result getCouponInfo(@PathVariable Long id){
        return Result.success(couponInfoService.getById(id));
    }

    @ApiOperation("添加优惠券信息")
    @PostMapping("saveOrUpdateCouponInfo")
    public Result saveOrUpdateCouponInfo(@RequestBody CouponInfo couponInfo){
        return Result.success(couponInfoService.saveOrUpdate(couponInfo));
    }

    @ApiOperation("删除优惠券信息")
    @DeleteMapping("removeCouponInfo/{id}")
    public Result removeCouponInfo(@PathVariable Long id){
        return Result.success(couponInfoService.removeById(id)).message("删除优惠券成功");
    }

    @ApiOperation("删除多个优惠券信息")
    @DeleteMapping("removeCouponInfoList")
    public Result removeCouponInfoList(@RequestBody List<Long> idList){
        return Result.success(couponInfoService.removeByIds(idList)).message("删除优惠券成功");
    }

    @ApiOperation("获取优惠券分页信息")
    @GetMapping("getCouponPageInfo/{page}/{limit}")
    public Result getCouponInfo(@PathVariable Long page, @PathVariable Long limit){
        Page<CouponInfo> infoPage = new Page<>(page,limit);
        return Result.success(couponInfoService.page(infoPage));
    }

    @ApiOperation("获取已使用优惠券分页信息")
    @GetMapping("getCouponUsedPageInfo/{page}/{limit}")
    public Result getCouponUsedPageInfo(@PathVariable Long page, @PathVariable Long limit, CouponUseQueryVo couponUseQueryVo){
        Page<CouponUse> usePage = new Page<>(page,limit);
        return Result.success(couponInfoService.getCouponUsedPageInfo(usePage, couponUseQueryVo));
    }

    @ApiOperation("发放优惠券")
    @PostMapping("issueCoupons/{id}")
    public Result issueCoupons(@PathVariable Long id){
        return Result.success(couponInfoService.issueCoupons(id));
    }
}

